﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using NetDon.OA.Interface;
using NetDon.OA.Interface.Admin;
using NetDon.OA.Interface.Location;
using NetDon.Utilities;

namespace NetDon.OA.Portal.Controls
{

    public class ProvinceDropDown: DropDownList
    {
        public ProvinceDropDown()
            : base()
        {
            this.Items.Clear();
            this.Items.AddRange(GetItems());
            this.Items.Insert(0, new ListItem(EnumUtilities.GetDescription(ListEmptyType.Select),string.Empty));
        }

        public override string DataTextField
        {
            get { return "Name"; }
            set { base.DataTextField = value; }
        }

        public override string DataValueField
        {
            get { return "ProvinceId"; }
            set { base.DataValueField = value; }
        }

        public ListItem[] GetItems()
        {
            var shippingService = ServiceContainer.GetService<ILocationService>();

            var provinces = shippingService.GetProvinces();


            return
              provinces.Select(
                  entity => new ListItem(entity.Name, entity.ProvinceId)).
                  ToArray();
        }


    }

    public class CityDropDown : DropDownList
    {
        public CityDropDown()
            : base()
        {
            this.Items.Clear();
        
            this.Items.Insert(0, new ListItem(EnumUtilities.GetDescription(ListEmptyType.Select), string.Empty));
        }

        public override string DataTextField
        {
            get { return "Name"; }
            set { base.DataTextField = value; }
        }

        public override string DataValueField
        {
            get { return "CityId"; }
            set { base.DataValueField = value; }
        }

        public void LoadDepartments(string ProvinceId)
        {
            this.Items.Clear();
            this.Items.AddRange(GetItems(ProvinceId));
            this.Items.Insert(0, new ListItem(EnumUtilities.GetDescription(ListEmptyType.Select), string.Empty));
        }

        public ListItem[] GetItems(string ProvinceId)
        {
            var shippingService = ServiceContainer.GetService<ILocationService>();

            var provinces = shippingService.GetCities(ProvinceId);


            return
              provinces.Select(
                  entity => new ListItem(entity.Name, entity.CityId)).
                  ToArray();


        }


    }
}